''' C. Water the Trees
https://codeforces.com/contest/1661/problem/C
'''
import io, os, sys
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline output = sys.stdout.write
DEBUG = os.environ.get('debug') not in [None, '0']
if DEBUG:
from inspect import currentframe, getframeinfo
from re import search
def debug(*args):
if not DEBUG: return
frame = currentframe().f_back
s = getframeinfo(frame).code_context[0]
r = search(r"\((.*)\)", s).group(1)
vnames = r.split(', ')
var_and_vals = [f'{var}={val}' for var, val in zip(vnames, args)]
prefix = f'{currentframe().f_back.f_lineno:02d}: '
print(f'{prefix}{", ".join(var_and_vals)}')
INF = float('inf')
def solve(N, A):
res = INF
mx = max(A)
for m in [mx, mx + 1]:
two = one = 0
for a in A:
two += (m - a) // 2
one += (m - a) % 2
if two - one >= 2:
t = (two - one + 1) // 3
one += 2 * t
two -= t
if two < one: res = min(res, one * 2 - 1)
elif two == one: res = min(res, one * 2)
elif two == one + 1: res = min(res, two * 2)
else: assert False
return res
def main():
T = int(input())
for _ in range(T):
N = int(input())
A = list(map(int, input().split()))
out = solve(N, A)
print(out)
if __name__ == '__main__':
main()
2099. Find Subsequence of Length K With the Largest Sum | 1608A - Find Array |
416. Partition Equal Subset Sum | 1446. Consecutive Characters |
1618A - Polycarp and Sums of Subsequences | 1618B - Missing Bigram |
938. Range Sum of BST | 147. Insertion Sort List |
310. Minimum Height Trees | 2110. Number of Smooth Descent Periods of a Stock |
2109. Adding Spaces to a String | 2108. Find First Palindromic String in the Array |
394. Decode String | 902. Numbers At Most N Given Digit Set |
221. Maximal Square | 1200. Minimum Absolute Difference |
1619B - Squares and Cubes | 1619A - Square String |
1629B - GCD Arrays | 1629A - Download More RAM |
1629C - Meximum Array | 1629D - Peculiar Movie Preferences |
1629E - Grid Xor | 1629F1 - Game on Sum (Easy Version) |
2148. Count Elements With Strictly Smaller and Greater Elements | 2149. Rearrange Array Elements by Sign |
2150. Find All Lonely Numbers in the Array | 2151. Maximum Good People Based on Statements |
2144. Minimum Cost of Buying Candies With Discount | Non empty subsets |